package com.spsy.pay.listener;

import com.alibaba.fastjson.JSON;
import com.rabbitmq.client.Channel;
import com.spsy.common.vo.OrderVo1;
import com.spsy.order.api.OrderApi;
import com.spsy.pay.config.RabbitmqConfig;
import com.spsy.pay.constant.RabbitMqConstant;
import com.spsy.pay.domain.TPaymentOrder;
import com.spsy.pay.service.ITPaymentOrderService;
import com.spsy.pay.vo.OrderPayEnum;
import com.spsy.pay.vo.RabbitVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @Author: Kyrie Irving
 * @Date: 2025/9/23 17:04
 * @Description:
 **/
@Component
@RabbitListener(queues = RabbitMqConstant.MQ_NAME)
@Slf4j
public class RabbitmqListener {

    @Autowired
    private ITPaymentOrderService itPaymentOrderService;

    @Autowired
    private OrderApi orderApi;

    @RabbitHandler
    public void handle(String str, Message message, Channel channel){
//        RabbitVo rabbitVo = JSON.parseObject(str,RabbitVo.class);
//                        List<TPaymentOrder> tPaymentOrders = itPaymentOrderService.selectTPaymentOrderList(TPaymentOrder.builder().merchantOrderNo(rabbitVo.getOrderId()).build());
//                if (tPaymentOrders.size()!=0 && tPaymentOrders.get(0).getOrderStatus()!= OrderPayEnum.success.getStatusValue().longValue()){
//                    int i = itPaymentOrderService.updatePayOrderByOrderId(TPaymentOrder.builder()
//                            .merchantOrderNo(rabbitVo.getOrderId()).orderStatus(OrderPayEnum.success.getStatusValue().longValue()).build());
//                    log.info("更新成功");
//                }
//
//                OrderVo1 orderVo = new OrderVo1();
//                orderVo.setOrderId(orderVo.getOrderId());
//                orderVo.setOrderStatus(1);
//                orderApi.updateOrderStatus(orderVo);
//                log.info("状态更新成功");

    }
}
